<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateActivityLogTable extends Migration
{
    /**
     * Run the migrations.
     */
    public function up()
    {
        Schema::connection(config('activitylog.database_connection'))->create(config('activitylog.table_name'), function (Blueprint $table) {
            $table->bigIncrements('id')->comment('ID');
            $table->string('log_name')->nullable()->comment('别名');
            $table->text('description')->comment('描述');
            $table->nullableMorphs('subject', 'subject');
            $table->nullableMorphs('causer', 'causer');
            $table->json('properties')->nullable()->comment('日志内容');
            $table->timestamp('created_at')->index()->nullable()->comment('创建时间');
            $table->timestamp('updated_at')->index()->nullable()->comment('修改时间');
            $table->index('log_name');
        });

        DB::statement('alter table'.' '.config('database.connections.mysql.prefix', '').'activity_logs comment "系统操作日志表"');
    }

    /**
     * Reverse the migrations.
     */
    public function down()
    {
        Schema::connection(config('activitylog.database_connection'))->dropIfExists(config('activitylog.table_name'));
    }
}
